package typesimport ()// Reference: https://www.ietf.org/rfc/rfc4120.txt// Section: 5.2.2// PrincipalName implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.2typePrincipalNamestruct { NameType int32`asn1:"explicit,tag:0"` NameString []string`asn1:"generalstring,explicit,tag:1"`}// NewPrincipalName creates a new PrincipalName from the name type int32 and name string provided.func ( int32, string) PrincipalName {returnPrincipalName{NameType: ,NameString: strings.Split(, "/"), }}// GetSalt returns a salt derived from the PrincipalName.func ( PrincipalName) ( string) string {var []byte = append(, ...)for , := range .NameString { = append(, ...) }returnstring()}// Equal tests if the PrincipalName is equal to the one provided.func ( PrincipalName) ( PrincipalName) bool {iflen(.NameString) != len(.NameString) {returnfalse }//https://tools.ietf.org/html/rfc4120#section-6.2 - the name type is not significant when checking for equivalencefor , := range .NameString {if .NameString[] != {returnfalse } }returntrue}// PrincipalNameString returns the PrincipalName in string form.func ( PrincipalName) () string {returnstrings.Join(.NameString, "/")}// ParseSPNString will parse a string in the format <service>/<name>@<realm>// a PrincipalName type will be returned with the name type set to KRB_NT_PRINCIPAL(1)// and the realm will be returned as a string. If the "@<realm>" suffix// is not included in the SPN then the value of realm string returned will be ""func ( string) ( PrincipalName, string) {ifstrings.Contains(, "@") { := strings.Split(, "@") = [len()-1] = strings.TrimSuffix(, "@"+) } = NewPrincipalName(nametype.KRB_NT_PRINCIPAL, )return}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.